package com.itheima;

import com.itheima.entry.cunMoney;
import com.itheima.entry.quMoney;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class controller {
    @Reference
    private serviceInterface serviceInterface;

    @GetMapping("/get/{accountId}/{password}")
    public String findById(@PathVariable(name = "accountId") String accountId,
                           @PathVariable(name = "password") String password) {

        String byId = serviceInterface.findById(accountId);
        boolean equals = password.equals(byId);
        if (equals) {
            return "登录成功";
        }
        return "登录失败";

    }

    @GetMapping("/money/{accountID}")
    public int findMoney(@PathVariable(name = "accountID") String accountID) {
        int money = serviceInterface.findMoney(accountID);
        return money;
    }

    @GetMapping("/zhuan/{qu}/{cun}/{money}")
    public String zhuanzhang(@PathVariable(value = "qu") String qu,
                             @PathVariable(name = "cun") String cun,
                             @PathVariable(value = "money") Integer money) {
        //转账分为两部，先取钱
        quMoney quMoney = new quMoney(qu, money);
        cunMoney cunMoney = new cunMoney(cun, money);
//        //后取钱
        serviceInterface.quMoney(quMoney);
        System.out.println(1/0);
        serviceInterface.cunMoney(cunMoney);

        return "successs";
    }


}
